package P1线性结构.LeetCode双指针;

public class LC209 {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = 0;
        int minLen = nums.length + 1;
        int sum = nums[left];
        while (true) {
            if (sum < target) {
                right++;
                if (right >= nums.length) {
                    break;
                }
                sum += nums[right];
            } else {
                int len = right - left + 1;
                minLen = Math.min(len, minLen);
                sum -= nums[left];
                left++;
                if (left > right) {
                    break;
                }
            }
        }
        return minLen == nums.length + 1 ? 0 : minLen;
    }
}